<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/4/4
 * Time: 15:25
 */

namespace Biz\service\trade;

use Biz\model\trade\ShopCourier as mShopCourier;
use Biz\cache\IniCourier as cInIniCourier;

class ShopCourier
{
    const  COURIER_CONFIG_FILE = "/home/adm_rsync_dir/courier.json";

    private static $courierData = [];

    protected static function _getCourierFileData()
    {
        if (empty(self::$courierData)) {
            self::$courierData =cInIniCourier::getCourier();
        }
    }

    public static function getCourierList($isRefund)
    {

        return mShopCourier::getCourierList($field = ['courier_id', 'courier_name'], $map = ['is_refund' => $isRefund, 'status' => mShopCourier::STATUS_NORMAL]);
    }

    public static function getCourierFileList()
    {
        self::_getCourierFileData();
        if (empty(self::$courierData)) {
            return [];
        }
        return self::$courierData['courier'];
    }

    public static function getRefundCourierInfo($courierId)
    {
        return mShopCourier::getCourier('*',['courier_id'=>$courierId]);
    }

    public static function getCourierFileInfo($courierId)
    {
        $result = [];

        self::_getCourierFileData();

        foreach (self::$courierData['courier'] as $courier) {
            if ($courier['courier_id'] == $courierId) {
                $result = $courier;
                break;
            }
        }
        return $result;
    }

    public static function getCourierFileInfoByTrackingMoreCode($trackingMoreCode)
    {
        $result = [];

        self::_getCourierFileData();

        foreach (self::$courierData['courier'] as $courier) {
            if ($courier['trackingmore_code'] == $trackingMoreCode) {
                $result = $courier;
                break;
            }
        }
        return $result;
    }

    public static function getCourierFileInfoByCourierBirdCode($courierbirdCode)
    {
        $result = [];

        self::_getCourierFileData();

        foreach (self::$courierData['courier'] as $courier) {
            if ($courier['courierbird_code'] == $courierbirdCode) {
                $result = $courier;
                break;
            }
        }
        return $result;
    }

    public static function getCourierIdByCourierName($courierName)
    {
        $result='';

        self::_getCourierFileData();

        foreach (self::$courierData['courier'] as $courier) {
            if ($courier['courier_name'] == $courierName) {
                $result = $courier['courier_id'];
                break;
            }
        }
        return $result;
    }

}